# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=clucene
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.3.4
pkgrel=2
pkgdesc="CLucene - a C++ search engine (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://clucene.sourceforge.io/"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-boost" "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://downloads.sourceforge.net/project/${_realname}/${_realname}-core-unstable/${pkgver:0:3}/${_realname}-core-${pkgver}.tar.gz"
        "${_realname}-core-${pkgver}.patch"
        010-pthread.patch
        020-gcc.patch)
sha256sums=('ddfdc433dd8ad31b5c5819cc4404a8d2127472a3b720d3e744e8c51d79732eab'
            'a3b0bb664231ed5e66384dd606422d7f6d9f0e6181f295056acfbe0b0d4d7c9c'
            '81f96824bf2ff0dc35288be6fa891df66841110fcd26f59c77025a96b831b637'
            '821471b0bc4e36571eea1d4d637e1c7881aae4ab18a78fed8be29771e38b58b0')

prepare() {
  cd "${srcdir}/${_realname}-core-${pkgver}"
  patch -Np1 -i "../${_realname}-core-${pkgver}.patch"
  patch -Np1 -i "../010-pthread.patch"
  patch -Np1 -i "../020-gcc.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_STATIC_LIBRARIES=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_STANDARD=98 \
    "../${_realname}-core-${pkgver}"

  cmake --build .
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" cmake --install .
}
